package com.cto.userserver.controller;

import com.common.log.anotation.AuditLog;
import com.common.log.config.MDCTraceUtils;
import com.cto.userserver.dto.UserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: qiu
 * @param:
 * @create: 2021-12-22
 **/
@RestController
@RequestMapping("/user")
@Data
@RefreshScope
@Slf4j
@Api("用户管理")
public class UserController {

    @Value("${server.port}")
    private int serverPort;

    @Value("${testProperties.xxx:1}")
    private String setTest;


    @GetMapping("/getUserInfo")
    @ResponseBody
    @AuditLog(operation = "获取用户信息")
    @ApiOperation("获取用户信息")
    public String getUserInfo(HttpServletRequest request) {
        String traceId = request.getHeader(MDCTraceUtils.TRACE_ID_HEADER);
        String spanId = request.getHeader(MDCTraceUtils.SPAN_ID_HEADER);
        //MDCTraceUtils.putTrace(traceId,spanId);
        log.error("getUserInfo获取traceId={},spanId={}",traceId,spanId);
        return "userId=" + serverPort + "_" + setTest+"time"+new Date();
    }


    @GetMapping
    @AuditLog(operation = "获取用户信息1")
    @ApiOperation("获取用户信息1")
    public Map<String,Object> getUserInfo1(HttpServletRequest request) {
        Map<String,Object> map = new HashMap<>();
        map.put("user", UserInfo.builder().birthDay(new Date()).name("秋").build());
        return map;
    }
}
